import sys
from context_functions import *

if len(sys.argv)<2: 
	exit()
filepath = sys.argv[1]

f = open(filepath,"r")

docs = []
terms = []
termdoc = {}
for line in f:
	d = line.replace("\n","").split(",")
	doc = int(d[0])
	term = int(d[1])
	if doc not in docs:
		docs.append(doc)
	if term not in terms:
		terms.append(term)
	if term not in termdoc:
		termdoc[term] = []
	termdoc[term].append(doc)

terms.sort()
docs.sort()

matrix = []
for t in terms:
	row = []
	for d in docs:
		if d in termdoc[t]:
			row.append(1)
		else:
			row.append(0)
	matrix.append(row)

fp = writeContext("toxic.rcf",matrix,terms,docs,context_name="Toxic Context", dataset_name="term_document")
